package com.tosmart.jorm.models;

import com.tosmart.jorm.annotation.*;
import com.tosmart.jorm.face.OptimisticLockSupport;

import java.io.Serializable;
import java.util.List;

/**
 * @author tosmart@gmail.com
 */
@JormEntity(
        table = "FAMILIES",
        optimisticLock = "VERSION"
)
public class Family implements OptimisticLockSupport, Serializable {

    public Family() {
    }

    public Family(int id) {
        this.id = id;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List getMembers() {
        return members;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer();
        sb.append("Family");
        sb.append("{address='").append(address).append('\'');
        sb.append(", id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", balance=").append(balance);
        sb.append(", members=").append(members);
        sb.append('}');
        return sb.toString();
    }

    public void setVersion(long version) {
        this.version = version;
    }

    public long getVersion() {
        return version;
    }

    @JormMap(
            primaryKey = true,
            autoGenerate = GenerateMethod.Increase
    )
    private int id;
    @JormMap
    private String name;
    @JormMap
    private String address;
    @JormMap
    private double balance;

    @JormReferList(
            entityClass = Person.class,
            foreignKeys = "FAMILY_ID"
    )
    private List members = null;

    // for logic: optimistic lock version
    private long version;
}
